#ifndef SINGLETON_H
#define SINGLETON_H
#include <memory>
#include <mutex>
#include <QDebug>


template<typename T>
class Singleton
{
public:

    Singleton(const Singleton<T> &other)=delete;
    Singleton<T>& operator=(const Singleton<T> &other)=delete;

    static std::shared_ptr<T> GetInstance()
    {
        static std::once_flag flag;
        std::call_once(flag,[&](){
            instance_ = std::shared_ptr<T>(new T());
        });
        return instance_;
    }





protected:
    Singleton<T>()=default;
    ~Singleton()
    {
        qDebug()<<"singleton desctruct\n";
    }
private:
      static std::shared_ptr<T> instance_;

};
template<typename T>
std::shared_ptr<T> Singleton<T>::instance_ = nullptr;


#endif // SINGLETON_H
